


//
//  BAAlbumModel.m
//  BabyAlbum
//
//  Created by master on 17/2/14.
//  Copyright © 2017年 master. All rights reserved.
//

#import "BAAlbumModel.h"
#import "BAResource.h"
@implementation BAAlbumModel

- (instancetype)init {
    self = [super init];
    
    return self;
}

- (NSString *)customDateShow {
    if(self.custom_date) {
        NSDateComponents *components = [[NSDate currentCalendar] components:NSCalendarUnitYear | kCFCalendarUnitMonth | kCFCalendarUnitDay fromDate:[NSDate dateWithTimeIntervalSince1970:[self.custom_date floatValue]]];
        NSString *currentDateString = [NSString stringWithFormat:@"%ld.%ld.%ld",(long)components.year,(long)components.month,(long)components.day];
        return currentDateString;
    }
    return @"";
}

- (NSString *)weekDayShow {
    if(self.custom_date) {
        return [[NSDate dateWithTimeIntervalSince1970:[self.custom_date floatValue]] weekDayShow];
    }
    return @"";
}
//TODO: 外部调用涉及多线程存在崩溃需要修改
- (NSArray<BAAlbumItem *> *)fetchResourceList {
    if(!self.album_id) {
        return @[];
    }
    NSArray<BAAlbumItem *> *array = [BADB resourceInAlbum:self.album_id];
    NSMutableArray *list = [NSMutableArray array];
    for (BAAlbumItem *item in array) {
        BAAlbumItem *itemFetched = [item autoFetch];
        if(itemFetched) {
            [list addObject:itemFetched];
        }
    }
    self.resourceList = list;
    return [list copy];
}

@end
